/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.apiGenerator.entity.separateInterface.entityInfo;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.caf.generator.property.PropertyGenerator;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.dataTypeInfo.DataTypeInfoGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.uniqueConstraintInfo.UniqueConstraintInfoGenerator;
import com.inspur.edp.cef.generator.apiGenerator.entity.separateInterface.EntityInterfaceGenCtx;
import com.inspur.edp.cef.spi.entity.info.EntityInfo;
import com.inspur.edp.das.commonmodel.collection.GspUniqueConstraintCollection;
import com.inspur.edp.das.commonmodel.entity.object.GspUniqueConstraint;

public class EntityInfoGenerator extends DataTypeInfoGenerator {
  private EntityInterfaceGenCtx parentContext;

  public EntityInfoGenerator(EntityInterfaceGenCtx parentContext) {
    super(parentContext);
    this.parentContext = parentContext;
  }


  // keyword:
  // ORIGINAL LINE: private new EntityInfoGeneratorContext getContext() { return
  // (EntityInfoGeneratorContext)((super.getContext() instanceof EntityInfoGeneratorContext) ?
  // super.getContext() : null); }
  @Override
  protected EntityInfoGeneratorContext getContext() {
    return (EntityInfoGeneratorContext)
        ((super.getContext() instanceof EntityInfoGeneratorContext) ? super.getContext() : null);
  }


  //region sealed
  @Override
  protected final ClassGeneratorContext createClassInfoContext() {
    return new EntityInfoGeneratorContext(parentContext);
  }

  @Override
  protected final void beforeInitialize() {
    super.beforeInitialize();
    parentContext.setDataTypeInfoType(
        new MediateType(super.compileUnit.getPackageName(), getName()));
  }

  @Override
  protected final String getName() {
    return dataType.getCode() + "EntityInfo";
  }

  @Override
  protected final java.util.ArrayList<ClassPropertyGenerator> createExtendPropertyGenerators() {

    java.util.ArrayList<ClassPropertyGenerator> list = super.createExtendPropertyGenerators();
    if (list == null) {
      list = new java.util.ArrayList<ClassPropertyGenerator>();
    }
    list.add(new UniqueConstraintInfoTypesDicGen(getContext()));

    java.util.ArrayList<ClassPropertyGenerator> extend = createEntityInfoExtendPropertyGenerators();
    if (extend != null && extend.size() > 0) {
      list.addAll(extend);
    }
    return list;
  }

  @Override
  protected final java.util.ArrayList<BaseGenerator> createExtendChildGenerators() {

    java.util.ArrayList<BaseGenerator> list = super.createExtendChildGenerators();
    if (list == null) {
      list = new java.util.ArrayList<BaseGenerator>();
    }

    GspUniqueConstraintCollection cons = getContext().getCommonObj().getContainConstraints();
    if (cons != null && cons.size() > 0) {
      for (GspUniqueConstraint con : cons) {
        list.add(createUniqueConsInfoGenerator(con));
      }
    }

    java.util.ArrayList<BaseGenerator> extend = createEntityInfoExtendChildGenerators();
    if (extend != null && extend.size() > 0) {
      list.addAll(extend);
    }
    return list;
  }

  //endregion


  //region 私有

  private UniqueConstraintInfoGenerator createUniqueConsInfoGenerator(GspUniqueConstraint con) {
    return new UniqueConstraintInfoGenerator(getContext(), con);
  }

  //endregion

  @Override
  protected java.lang.Class getParentClassType() {
    return EntityInfo.class;
  }

  protected java.util.ArrayList<ClassPropertyGenerator> createEntityInfoExtendPropertyGenerators() {
    return null;
  }

  protected java.util.ArrayList<BaseGenerator> createEntityInfoExtendChildGenerators() {
    return null;
  }
}
